import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
      headerImg:'',
      topNavMenu:[],
      powerList:[]
  },
  mutations: {
    setHeaderImg(state,headerImg){
        state.headerImg=headerImg
    },
    //添加头部标签栏
    addTopNavMenu(state,topNavMenu){
     for (let i=0; i<state.topNavMenu.length; i++){
       if (state.topNavMenu[i].pid===topNavMenu.pid)return
     }
      state.topNavMenu.push(topNavMenu)
    },
    //删除头部标签栏
    removeTopNavMenu(state,pid){
      state.topNavMenu=state.topNavMenu.filter(item=>item.pid!=pid)
    },
      //初始化权限数组
      initPowerList(state,powerListItem){
        state.powerList=powerListItem;
      }

  },
  actions: {
      //初始化权限数据
      initPoserListAction(context,val){
         let pidList=val.split(",");
         for(let i=0;i<pidList.length;i++){
             pidList[i]=parseInt(pidList[i]);
         }
          context.commit("initPowerList",pidList)
      }
  },
  modules: {

  },
})
